/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#include "gamelib.h"


odVec4	colorTable[32] = {
	odVec4(0.00f, 0.00f, 0.00f, 1.00f),
	odVec4(1.00f, 0.00f, 0.00f, 1.00f),
	odVec4(0.00f, 1.00f, 0.00f, 1.00f),
	odVec4(1.00f, 1.00f, 0.00f, 1.00f),
	odVec4(0.00f, 0.00f, 1.00f, 1.00f),
	odVec4(0.00f, 1.00f, 1.00f, 1.00f),
	odVec4(1.00f, 0.00f, 1.00f, 1.00f),
	odVec4(1.00f, 1.00f, 1.00f, 1.00f),
	odVec4(0.75f, 0.75f, 0.75f, 1.00f),
	odVec4(0.50f, 0.50f, 0.50f, 1.00f),
	odVec4(0.25f, 0.25f, 0.25f, 1.00f),
	odVec4(0.50f, 0.00f, 0.00f, 1.00f),
	odVec4(0.00f, 0.50f, 0.00f, 1.00f),
	odVec4(0.50f, 0.50f, 0.00f, 1.00f),
	odVec4(0.00f, 0.00f, 0.50f, 1.00f),
	odVec4(0.00f, 0.50f, 0.50f, 1.00f),
	odVec4(0.50f, 0.00f, 0.50f, 1.00f),
	odVec4(1.00f, 0.50f, 0.00f, 1.00f),
	odVec4(0.00f, 0.50f, 1.00f, 1.00f),
	odVec4(1.00f, 0.00f, 0.50f, 1.00f),
	odVec4(0.25f, 0.50f, 0.50f, 1.00f),
	odVec4(1.00f, 1.00f, 0.50f, 1.00f),
	odVec4(0.50f, 0.00f, 1.00f, 1.00f),
	odVec4(0.50f, 0.25f, 0.00f, 1.00f),
	odVec4(1.00f, 0.50f, 0.75f, 1.00f),
	odVec4(0.50f, 0.50f, 1.00f, 1.00f),
	odVec4(1.00f, 0.50f, 0.50f, 1.00f),
	odVec4(0.00f, 0.25f, 0.00f, 1.00f),
	odVec4(0.50f, 1.00f, 0.50f, 1.00f),
	odVec4(0.00f, 0.50f, 0.75f, 1.00f),
	odVec4(0.50f, 1.00f, 1.00f, 1.00f),
	odVec4(1.00f, 0.50f, 1.00f, 1.00f)
};


/*
 ==================
 PackColor
 ==================
*/
dword PackColor (const odVec4 &color){

	dword	c;

	((byte *)&c)[0] = M_FtolFast(color[0] * 255.0f);
	((byte *)&c)[1] = M_FtolFast(color[1] * 255.0f);
	((byte *)&c)[2] = M_FtolFast(color[2] * 255.0f);
	((byte *)&c)[3] = M_FtolFast(color[3] * 255.0f);

	return c;
}

/*
 ==================
 PackColor4
 ==================
*/
dword PackColor4 (float r, float g, float b, float a){

	dword	c;

	((byte *)&c)[0] = M_FtolFast(r * 255.0f);
	((byte *)&c)[1] = M_FtolFast(g * 255.0f);
	((byte *)&c)[2] = M_FtolFast(b * 255.0f);
	((byte *)&c)[3] = M_FtolFast(a * 255.0f);

	return c;
}

/*
 ==================
 UnpackColor
 ==================
*/
void UnpackColor (dword c, odVec4 &color){

	color[0] = ((byte *)&c)[0] * (1.0f/255);
	color[1] = ((byte *)&c)[1] * (1.0f/255);
	color[2] = ((byte *)&c)[2] * (1.0f/255);
	color[3] = ((byte *)&c)[3] * (1.0f/255);
}

/*
 ==================
 UnpackColor4
 ==================
*/
void UnpackColor4 (dword c, float *r, float *g, float *b, float *a){

	*r = ((byte *)&c)[0] * (1.0f/255);
	*g = ((byte *)&c)[1] * (1.0f/255);
	*b = ((byte *)&c)[2] * (1.0f/255);
	*a = ((byte *)&c)[3] * (1.0f/255);
}
